﻿@using FwProject.Com.Dto
@using FwProject.ShoppingMall.Com
@model ContentManageOutputDto
@section styles{
    <link href="~/css/search-suggest.min.css" rel="stylesheet" />
}
<style>

    .search-suggest .content {
        max-height: 200px;
        overflow-y: scroll;
    }

    .search-suggest {
        z-index: 19891020;
    }

    .hidden {
        display: none;
    }
</style>
<form id="form0" class="layui-form" action="@Url.Action("Edit",new { id=ViewBag.Id})" method="post" novalidate="novalidate" data-ajax="true" data-ajax-begin="LockAjaxCallbackBack" data-ajax-success="ReloadAjaxCallbackgoback" data-ajax-failure="FailureAjaxCallback" data-ajax-method="Post" role="form" lay-filter="form1">
    <div class="layui-form layui-form-pane" style="padding:10px;">
        <div class="layui-form-item">
            @Html.LabelFor(o => o.ContnetTypeId, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.DropDownListFor(o => o.ContnetTypeId, ViewBag.Types as IEnumerable<SelectListItem>)
                @Html.ValidationMessageFor(o => o.ContnetTypeId)
            </div>
        </div>
        <div class="layui-form-item">
            @Html.LabelFor(o => o.Title, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.TextBoxFor(o => o.Title, new { @class = "layui-input" })
                @Html.ValidationMessageFor(o => o.Title)
            </div>
        </div>

        <div class="layui-form-item">
            @Html.LabelFor(o => o.AccessType, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                <enums class="layui-input layui-unselect" asp-name="AccessType" asp-valuetype="2" lay-filter="filter" asp-enum="typeof(AccessType)" asp-value="@Model.AccessType.ToString()"></enums>
                @Html.ValidationMessageFor(o => o.AccessType)
            </div>
        </div>
        <div class="layui-form-item @(Model.AccessType!= AccessType.Url?"hidden":"")">
            <label class="layui-form-label">数据-URL</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="data_url" name="@(Model.AccessType!= AccessType.Url?"":"Data")" value="@(Model.AccessType!= AccessType.Url?"":Model.Data)" placeholder="请输入网址" />
            </div>
        </div>
        <div class="layui-form-item @(Model.AccessType!= AccessType.Details?"hidden":"")">
            <label class="layui-form-label">数据-商品</label>
            <div class="layui-input-block">
                <input type="text" id="search-shopProduct" class="layui-input" placeholder="请选择商品" value="@Model.ShopProductName">
                <input type="hidden" id="data_detils" name="@(Model.AccessType!= AccessType.Details?"":"Data")" value="@(Model.AccessType!= AccessType.Details?"":Model.Data)" />
            </div>
        </div>
        <div class="layui-form-item layui-form-text" style="margin-bottom:100px;">
            @Html.LabelFor(o => o.Content, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.TextAreaFor(o => o.Content, new { })
                @Html.ValidationMessageFor(o => o.Content)
            </div>
        </div>
        <div class="layui-layer-btn layui-layer-btn-" style="padding:8px 12px;z-index:1000;position: fixed;bottom:0;left: 1px;width: 98%;height: 50px; background:rgba(230,230,230,0.8)">
            <a id="save" class="layui-layer-btn0" lay-submit="" lay-filter="saveprops">保存</a>
        </div>
    </div>
</form>

@section scripts{
    <script src="~/js/main.js"></script>
    <script src="~/js/search-suggest.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="~/lib/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="~/lib/ueditor/ueditor.all.min.js"></script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="~/lib/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript">
        var ue = UE.getEditor('Content', {
            initialFrameWidth: null,//设置为null即可
            initialFrameHeight: 650
        });
        var form, layer, layedit;
        layui.use(['form', 'layedit', 'layer'], function () {
            layedit = layui.layedit;
            form = layui.form;
            layer = layui.layer;

            //自定义验证规则
            form.verify({
                required: function (value) {
                    if (value == "") {
                        return '必填项不能为空';
                    }
                }
            });

            form.on('select(filter)', function (data) {
                if (data.value == 'Details') {
                    $("#data_detils").parent().parent().show();
                    $("#data_url").parent().parent().hide();
                    $("#data_detils").attr('name', 'Data');
                    $("#data_url").attr('name', '');

                } else if (data.value == 'Url') {
                    $("#data_detils").parent().parent().hide();
                    $("#data_url").parent().parent().show();
                    $("#data_detils").attr('name', '');
                    $("#data_url").attr('name', 'Data');
                }

                //console.log(data.elem); //得到select原始DOM对象
                //console.log(data.value); //得到被选中的值
                //console.log(data.othis); //得到美化后的DOM对象
            });

        })

        var search = $("#search-shopProduct").searchSuggest({
            url: "/Commodity/GetSearchSuggest?keyword=", /*优先从url ajax 请求 json 帮助数据*/
            jsonp: null,
            width: 200,   /*提示框的宽度，缺省为输入框的宽度相同*/
            topoffset: 16,  /*提示框与输入框的距离，缺省为5*/
            style: 'list',
            cssFile: '/css/search-suggest.min.css',
            selectCallback: function (d) {
                $("#data_detils").val(d.id);
            }
        });

        function ReloadAjaxCallbackgoback(data, successInfo) {
            if (data.success) {
                layer.msg('保存成功！')
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭当前iframe页面
            } else {
                layer.msg('保存失败：' + successInfo);
            }
        }

        $('#save').on('click', function () {
            $('#form0').submit();
        });

        $(document).ready(function () {

        });
    </script>
}

